//
//  UIImage+WLSVGKit.m
//  SleepApp
//
//  Created by chuangqi on 2021/4/8.
//  Copyright © 2021 RiceWang. All rights reserved.
//

#import "UIImage+WLSVGKit.h"
#import <SVGKit/SVGKit.h>
#import "UIImage+Color.h"
@implementation UIImage (WLSVGKit)
/** 读取svg格式图片 */
+(UIImage *)svgName:(NSString *)svgName{
    return [self svgName:svgName size:CGSizeZero];
}
/** 读取svg格式图片 以宽为准 等比例修改大小 */
+(UIImage *)svgName:(NSString *)svgName width:(CGFloat)width{
    SVGKImage *svgImage = [SVGKImage imageNamed:svgName];
    if (width){
        svgImage.size = CGSizeMake(width, svgImage.size.height/svgImage.size.width * width);
    }
    return svgImage.UIImage;
}
/** 读取svg格式图片 以高为准 等比例修改大小 */
+(UIImage *)svgName:(NSString *)svgName height:(CGFloat)height{
    SVGKImage *svgImage = [SVGKImage imageNamed:svgName];
    if (height){
        svgImage.size = CGSizeMake(svgImage.size.width/svgImage.size.height * height, height);
    }
    return svgImage.UIImage;
}
/** 读取svg格式图片 并修改大小 */
+(UIImage *)svgName:(NSString *)svgName size:(CGSize)size{
    SVGKImage *svgImage = [SVGKImage imageNamed:svgName];
    if (!CGSizeEqualToSize(size, CGSizeZero)){
        svgImage.size = size;
    }
    return svgImage.UIImage;
}
/** 读取svg格式图片 并重新上色 */
+(UIImage *)svgName:(NSString *)svgName tintColor:(UIColor *)tintColor{
    UIImage *image = [self svgName:svgName];
    return [image imageChangeColor:tintColor];
}
@end
